<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>导入数据</title>
    <link rel="stylesheet" href="../assets/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../assets/style/admin.css">
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <script src="../assets/layui/layui.js"></script>
    <script src="../assets/js/common.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <script src="../common/header.js"></script>
    <!-- 内容主体区域 -->
    <div id="LAY_app_body">
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-header">
                            <a href="../../code/customer_source/add.html" class="layui-btn layui-btn-sm">1、导入数据</a>
                            <i class="layui-icon layui-icon-right" style="font-size: 20px;"></i>
                            <a href="../../code/message/editGroupEnhance.html" class="layui-btn layui-btn-sm layui-btn-normal">2、编辑验证消息</a>
                            <i class="layui-icon layui-icon-right" style="font-size: 20px;"></i>
                            <a href="../add_friend_plan/add.html" class="layui-btn layui-btn-sm layui-btn-normal">3、创建加人计划</a>
                        </div>
                        <div class="layui-card-body">
                            <form id="addForm" class="layui-form" action="" enctype="multipart/form-data">
                                <input type="hidden" name="id" value="">
                                <div class="layui-form-item" style="display: none;">
                                    <label class="layui-form-label">数据类型</label>
                                    <div class="layui-input-block">
                                        <input type="radio" name="type_level0" value="1" checked="checked" title="电商平台"  lay-filter="switchType" />
                                        <input type="radio" name="type_level0" value="2" checked="checked" title="电销直销"  lay-filter="switchType" />
                                        <input type="radio" name="type_level0" value="3" checked="checked" title="微商"  lay-filter="switchType" />
                                        <input type="radio" name="type_level0" value="4" checked="checked" title="O2O"  lay-filter="switchType" />
                                    </div>
                                </div>
                                <div class="layui-form-item type-sub-block type-sub-block-1" style="display: none;">
                                    <label class="layui-form-label">平台</label>
                                    <div class="layui-input-block">
                                        <input type="radio" name="type_level1" value="7" title="淘宝" class="type-children type-children-1"  />
                                        <input type="radio" name="type_level1" value="8" title="天猫" class="type-children type-children-1"  />
                                        <input type="radio" name="type_level1" value="9" title="京东" class="type-children type-children-1"  />
                                        <input type="radio" name="type_level1" value="10" title="拼多多" class="type-children type-children-1"  />
                                        <input type="radio" name="type_level1" value="43" title="蘑菇街" class="type-children type-children-1"  />
                                        <input type="radio" name="type_level1" value="44" title="唯品会" class="type-children type-children-1"  />
                                        <input type="radio" name="type_level1" value="45" title="小红书" class="type-children type-children-1"  />
                                        <input type="radio" name="type_level1" value="46" title="微店" class="type-children type-children-1"  />
                                        <label class="layui-word-aux">其他平台可联系负责人</label>                                </div>
                                </div>
                                <div class="layui-form-item type-sub-block type-sub-block-1" style="display: none;">
                                    <label class="layui-form-label">类目</label>
                                    <div class="layui-input-block">
                                        <input type="radio" name="type_level2" value="25" title="运动户外" class="type-children type-children-1"  />
                                        <input type="radio" name="type_level2" value="14" title="手机数码" class="type-children type-children-1"  />
                                        <input type="radio" name="type_level2" value="15" title="女装" class="type-children type-children-1"  />
                                        <input type="radio" name="type_level2" value="26" title="男装" class="type-children type-children-1"  />
                                        <input type="radio" name="type_level2" value="40" title="鞋靴" class="type-children type-children-1"  />
                                        <input type="radio" name="type_level2" value="42" title="食品" class="type-children type-children-1"  />
                                        <input type="radio" name="type_level2" value="28" title="百货" class="type-children type-children-1"  />
                                        <input type="radio" name="type_level2" value="27" title="家电" class="type-children type-children-1"  />
                                        <input type="radio" name="type_level2" value="29" title="内衣配饰" class="type-children type-children-1"  />
                                        <input type="radio" name="type_level2" value="30" title="美妆洗护" class="type-children type-children-1"  />
                                        <input type="radio" name="type_level2" value="41" title="母婴" class="type-children type-children-1"  />
                                        <input type="radio" name="type_level2" value="31" title="家居家纺" class="type-children type-children-1"  />
                                        <input type="radio" name="type_level2" value="39" title="生活服务" class="type-children type-children-1"  />
                                        <input type="radio" name="type_level2" value="32" title="箱包" class="type-children type-children-1"  />
                                        <input type="radio" name="type_level2" value="33" title="家装" class="type-children type-children-1"  />
                                        <input type="radio" name="type_level2" value="34" title="整车车品" class="type-children type-children-1"  />
                                        <input type="radio" name="type_level2" value="35" title="珠宝配饰" class="type-children type-children-1"  />
                                        <input type="radio" name="type_level2" value="36" title="生鲜" class="type-children type-children-1"  />
                                        <input type="radio" name="type_level2" value="37" title="鲜花宠物" class="type-children type-children-1"  />
                                        <input type="radio" name="type_level2" value="38" title="图书乐器" class="type-children type-children-1"  />
                                        <input type="radio" name="type_level2" value="16" title="现代农业" class="type-children type-children-1"  />
                                        <label class="layui-word-aux">其他类目可联系负责人</label>                                </div>
                                </div>
                                <div class="layui-form-item type-sub-block type-sub-block-1" style="display: none;">
                                    <label class="layui-form-label">数据来源</label>
                                    <div class="layui-input-block">
                                        <input type="radio" name="type_level3" value="48" title="店铺导出无修改" class="type-children type-children-1"  />
                                        <input type="radio" name="type_level3" value="49" title="自定义模板" class="type-children type-children-1"  />
                                    </div>
                                </div>
                                <div class="layui-form-item type-sub-block type-sub-block-2" style="display: none;">
                                    <label class="layui-form-label">行业</label>
                                    <div class="layui-input-block">
                                        <input type="radio" name="type_level1" value="17" title="金融" class="type-children type-children-2"  />
                                        <input type="radio" name="type_level1" value="18" title="教育" class="type-children type-children-2"  />
                                        <input type="radio" name="type_level1" value="19" title="房产" class="type-children type-children-2"  />
                                        <input type="radio" name="type_level1" value="50" title="咨询" class="type-children type-children-2"  />
                                        <label class="layui-word-aux">其他行业可联系负责人</label>                                </div>
                                </div>
                                <div class="layui-form-item type-sub-block type-sub-block-3" style="display: none;">
                                    <label class="layui-form-label">行业</label>
                                    <div class="layui-input-block">
                                        <input type="radio" name="type_level1" value="20" title="女装" class="type-children type-children-3"  />
                                        <input type="radio" name="type_level1" value="21" title="女鞋" class="type-children type-children-3"  />
                                        <input type="radio" name="type_level1" value="22" title="母婴" class="type-children type-children-3"  />
                                        <label class="layui-word-aux">其他行业可联系负责人</label>                                </div>
                                </div>
                                <div class="layui-form-item type-sub-block type-sub-block-4" style="display: none;">
                                    <label class="layui-form-label">行业</label>
                                    <div class="layui-input-block">
                                        <input type="radio" name="type_level1" value="23" title="餐饮" class="type-children type-children-4"  />
                                        <input type="radio" name="type_level1" value="24" title="美容保健" class="type-children type-children-4"  />
                                        <label class="layui-word-aux">其他行业可联系负责人</label>                                </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">数据名称</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="name" lay-verify="name" autocomplete="off" placeholder="请输入数据名称" class="layui-input" value="">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">上传数据</label>
                                    <div class="layui-input-inline">
                                        <input type="file" name="sourceFile" placeholder="请上传数据文件" required lay-verify="sourceFile" autocomplete="off" class="layui-input">
                                        <div class="layui-form-mid">txt文件，一个手机号一行，不要增加额外内容</div>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-input-block">
                                        <div class="layui-form-mid" style="color: red;">如果您的微信为国外手机号注册，请在上传的手机号前面添加 +86，否则无法加好友</div>
                                    </div>
                                </div>
                                <div class="layui-form-item" style="display: none;">
                                    <label class="layui-form-label">状态</label>
                                    <div class="layui-input-inline">
                                        <input type="radio" name="status" value="1"
                                               title="启用" checked>
                                        <input type="radio" name="status" value="0"
                                               title="禁用" >
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-input-block">
                                        <a class="layui-btn" lay-submit lay-filter="formSubmit">保存</a>
                                        <a class="layui-btn layui-btn-primary" href="index.html">取消</a>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>
        var switchType;
        layui.use(['form'], function(){
            var $ = layui.$
                ,form = layui.form;

            form.verify({
                sourceFile: function(value){
                    if(value.length < 1){
                        return '请上传数据文件';
                    }
                },
                name: function(value){
                    if(value.length < 1){
                        return '请填写数据名称';
                    }
                }
            });

            //监听提交
            form.on('submit(formSubmit)', function(data){
                layer.msg('提交中', {
                    shadeClose: false
                    ,icon: 16
                    ,shade: 0.01
                });
                var check = checkType();
                if (!check) return false;

                var data2 = new FormData($('#addForm')[0]);
                $.ajax({
                    type: "POST",
                    url: "/customer_source/save",
//                data: data.field,
                    data: data2,
                    cache: false,
                    contentType: false,
                    processData: false,
                    success:function(response){
                        var dataObj=$.parseJSON(response);
                        if (dataObj.code===0) {
                            layer.msg('数据提交成功', {icon: 6});
                            setTimeout(function(){
                                location.href = '/customer_source/index';
                            }, 1000);
                        } else {
                            layer.msg(dataObj.msg, {icon: 5});
                        }
                    },
                    error: function (request, status, error) {
                        layer.msg('哦噢，网络开小差了', {icon: 5});
                    }
                });
                return false;
            });

            form.on('radio(switchType)', function(data){
//            console.log(data.elem); //得到radio原始DOM对象
//            console.log(data.value); //被点击的radio的value值
                var typeId = data.value;
                $('.type-sub-block').css('display', 'none');
                $('.type-sub-block-'+typeId).css('display', 'block');

                var radios = $('.type-children');
                radios.each(function () {
                    $(this).removeAttr("checked");
                });
                form.render();
            });

            var checkType = function () {
                var typeLevel0Id = $("input[name='type_level0']:checked").val();
                if (typeLevel0Id == undefined || typeLevel0Id <= 0) {
                    layer.msg('请完善数据类型选项', {icon: 5});
                    return false;
                }
                return true;
            };
        });
    </script>
</div>
</body>
</html>
